
import type { Ref } from "vue";
import type { DataItem } from "@/type/type";
import { getAllUsers } from "@/api/user-api/userApi";

const dataSource: Ref<DataItem[]> = ref([
  {
    id: '1',
    username: 'admin',
    userAccount: 'admin123',
    avatarUrl: 'https://example.com/avatar1.jpg',
    gender: 'male',
    userPassword: 'adminpass',
    phone: '1234567890',
    email: '',
    userStatus: '',
    createTime: '',
    updateTime: '',
    isDelete: '',
    userRole: '',
  },
  {
    id: '2',
    username: 'user',
    userAccount: 'user123',
    avatarUrl: 'https://example.com/avatar2.jpg',
    gender: 'female',
    userPassword: 'userpass',
    phone: '0987654321',
    email: '',
    userStatus: '',
    createTime: '',
    updateTime: '',
    isDelete: '',
    userRole: '',
  },
]);

// import axios from 'axios';
const getUsersInfo = async (param:string|null) => {
    if (!param) {
        return null;
    }
  try {
    // 将数据赋值给响应式引用
    dataSource.value = await getAllUsers();
    return dataSource.value.find(
      e => e.userAccount === param,
    );
  } catch (error) {
    console.error('Error fetching data:', error);
  }
}

export default getUsersInfo;